{include file="public/head"/}
<div class="container-fluid" id="listboxing">
	<div class="row clearfix">
		<div class="col-md-12 column">
			<div class="alert alert-dismissable alert-info" id="headeralert">
				<button type="button" class="close">×</button>
				<p></p>
			</div>
		</div>
	</div>
	<div class="ntDesktop">
		<div class="ntDesktop-head">配货界面（装箱员）/ 装箱单编辑</div>

		<div class="row">
			<div class="col-md-12">
				<div class="panel panel-default">
					<div class="panel-body">
						<div class="col-md-1">
							<small class="gray">订单号</small><br>
							{{formatUnit(topdata.id,'ID')}}
						</div>
						<div class="col-md-7">
							<small class="gray">公司</small><br>
							<div class="text-1line">{{topdata.company_name}}</div>
						</div>
						<div class="col-md-1">
							<small class="gray">业务员</small><br>
							{{topdata.saler_name}}
						</div>
						<div class="col-md-1">
							<small class="gray">对货员</small><br>
							{{topdata.checker_name}}
						</div>
					</div>
				</div>
			</div>
		</div>

		<div class="row" style="padding-bottom:0.5rem">
			<div class="col-md-2">
				<a href="/admin/finance/enchaseboxer" class="col-md-6 btn btn-default">返回列表</a>
			</div>
			<div class="col-md-2 text-right">
				<button type="button" class="btn btn-primary" @click="addpack">
					<span class="fa fa-arrow-right"></span> 添加到装箱单
				</button>
			</div>
			<div class="col-md-2">
			</div>
			<div class="col-md-1 lh-3">
				待发区 <span class="required"></span>
			</div>
			<div class="col-md-4">
				<select name="" class="form-control" v-model="area_id">
					<option value="" selected>{:strtoupper(lang('please_select'))}</option>
					<option :value="item.id" v-for="(item,index) in topdata.warsedata">
						{{item.name}}
					</option>
				</select>
			</div>
			<div class="col-md-1 text-right">
				<button class="col-md-12 btn btn-primary" :disabled="isdisadble" @click="subfun"><span class="fa fa-save"></span>保存</button>
			</div>
		</div>

		<div class="row">
			<div class="col-md-4">
				<div class="panel panel-default">
					<div class="panel-heading">
						订单内容
					</div>
					<table class="table">
						<thead>
						<tr>
							<th></th>
							<th width="56%">产品</th>
							<th>箱规</th>
							<th width="16%">数量/未装</th>
							<th></th>
						</tr>
						</thead>
						<tbody>
						<!--空箱-->
						<tr>
							<td></td>
							<td>
								<div class="pro">
									<div class="pro-icon"><img src="/icon/0000/0000_48.jpg" border="0" width="48px" height="48px" alt=""></div>
									<div class="pro-name">空箱</div>
								</div>
							</td>
							<td align="right">
								50x40x30<small class="unit">CM</small>
							</td>
							<td></td>
							<td>
								<button data-toggle="modal" @click="remark(-1)" data-target="#box_remarkModal" class="btn btn-sm btn-info">
									<span class="fa fa-arrow-right"></span>
								</button>
							</td>
						</tr>
						<tr v-for="(item ,index) in prodata" :key="item.id">
							<!--只有还没有装的才显示-->
							<td><input v-if="item.quantityqty>0" type="checkbox" @click="onesel(index)"></td>
							<td>
								<div class="pro">
									<div class="pro-icon">
										<img :src="item.img_url" border="0" width="48px"
											 height="48px">
									</div>
									<div class="pro-name">
										<small> {{formatUnit(item.prochar_id,'ID') + (item.brand_name ? ' / '+item.brand_name :'')+ (item.model ? ' / '+item.model :'')}}
										</small>
										<br>
										{{item.pro_name}}
									</div>
								</div>
							</td>
							<td align="right">
								{{item.prochar_qty}}<small class="unit">PCS/CTN</small><br>
								{{item.ctn_size}}<small class="unit">CM</small>
							</td>
							<td align="right">
								<!--产品数量、未装数量、未装数量/每箱数量(保留两位小数)-->
								{{item.qty}}<small class="unit">PCS</small><br>
								<span class="green">{{item.quantityqty==0?'-':item.quantityqty}}</span><small class="unit">PCS</small><br>
								<span class="green">{{formatUnit(item.quantityqty/item.prochar_qty,'CTN')}}</span><small class="unit">CTN</small>
							</td>
							<td>
								<!--添加产品-->
								<button v-if="item.quantityqty>0" class="btn btn-sm btn-info" @click="addpro(index)">
									<span class="fa fa-arrow-right"></span>
								</button>
							</td>
						</tr>
						</tbody>
					</table>
				</div>
			</div>
			<div class="col-md-8">
				<div class="panel panel-default">
					<div class="panel-heading">
						装箱内容
					</div>
					<table class="table">
						<thead>
						<tr>
							<th width="8%">箱号</th>
							<th width="8%">箱数</th>
							<th>产品</th>
							<th width="8%">数量<small class="unit">PCS</small></th>
							<th width="16%">箱规<small class="unit">LxWxH</small></th>
							<th width="10%">重量<small class="unit">KGS</small></th>
							<th width="8%">备注</th>
							<th width="10%">操作</th>
						</tr>
						</thead>
						<tbody>
						<!--装箱单-->
						<template v-for="(item ,index) in sale_packdata" v-if="sale_packdata.length>0">
							<!--装箱单下面的产品-->
							<tr v-for="(itemdata,itemdataIndex) in item.data">
								<template v-if="itemdataIndex == 0">
									<!--箱号/箱数-->
									<td><input min="1" type="number" class="form-control text-right" v-model="item.number"></td>
									<td><input min="1" @input="changeqty" type="number" class="form-control text-right" v-model="item.ctns"></td>
								</template>
								<template v-else>
									<td></td>
									<td></td>
								</template>
								<!--装箱的产品-->
								<td>
									<div class="pro" >
										<div class="pro-icon">
											<img :src="itemdata.img_url" border="0" width="48px"
												 height="48px">
										</div>
										<div class="pro-name">
											<small v-if="itemdata.prochar_id>0"> {{formatUnit(itemdata.prochar_id,'ID') + (itemdata.brand_name ? ' / '+itemdata.brand_name :'')+ (itemdata.model ? ' / '+itemdata.model :'')}}
											</small>
											<br>
											{{itemdata.pro_name}}
										</div>
									</div>
								</td>
								<!--实际每箱装的数量-->
								<td><input type="number" min="1" @input="changeqty" class="form-control" v-model="itemdata.reality_qty"></td>

								<template v-if="itemdataIndex == 0">
									<!--箱规、重量、备注-->
									<td><input type="text" class="form-control" v-model="item.ctn_size"></td>
									<td><input type="number" class="form-control text-right" v-model="item.ctn_kgs"></td>
									<td>
										<button v-if="item.remark" @click="remark(index)" type="button" class="btn btn-sm btn-default" data-toggle="modal" data-target="#box_remarkModal">备注</button>
									</td>
								</template>
								<template v-else>
									<td></td>
									<td></td>
									<td></td>
								</template>
								<td align="right">
									<template v-if="itemdataIndex == 0">
										<button type="button" class="btn btn-sm btn-primary" @click="editpro(index)" data-toggle="modal" data-target="#box_editModal">编辑</button>
									</template>
									<button type="button" class="btn btn-sm btn-default" @click="delpack(index,itemdataIndex,1)">删除</button>
								</td>
							</tr>
						</template>
						</tbody>
						<tfoot>
						<tr>
							<td colspan="8" align="right">
								合计箱数: {{formatUnit(sumnum[0],'CTN')}}<small class="unit">CTN</small> /
								体积: {{formatUnit(sumnum[1],'CBM')}} <small class="unit">CBM</small> /
								重量: {{formatUnit(sumnum[2],'KGS')}}<small class="unit">KGS</small>
							</td>
						</tr>
						</tfoot>
					</table>
				</div>
			</div>

		</div>

	</div>
	<!-- 配货-装箱 备注 弹窗开始 -->
	<div class="modal fade" id="box_remarkModal" tabindex="-1" role="dialog" aria-hidden="true">
		<div class="modal-dialog modal-lg" style="width:60%">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
					<h4 class="modal-title">装箱(箱号: {{number}} )备注内容编辑</h4>
				</div>
				<div class="modal-body">
					<div class="row clearfix">
						<div class="col-md-12 column">
							<div class="alert alert-dismissable alert-info">
								<button type="button" class="close">×</button>
								<p></p>
							</div>
						</div>
					</div>
					<div class="row">
						<div class="col-md-1 lh-3">备注</div>
						<div class="col-md-11">
							<textarea name="" v-model="remakspro"  rows="5" class="form-control"></textarea>
						</div>
					</div>

				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">
						<span class="glyphicon glyphicon-remove"></span>取消
					</button>
					<button type="button" @click="saveremark" class="btn btn-primary" style="padding-left:24px;padding-right:24px">
						<span class="glyphicon glyphicon-floppy-disk"></span>保存备注
					</button>
				</div>
			</div>
		</div>
	</div>
	<!-- 配货-装箱 添加 弹窗开始 -->
	<div class="modal fade" id="box_editModal" tabindex="-1" role="dialog" aria-hidden="true">
		<div class="modal-dialog modal-lg" style="width:70vw">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
					<h4 class="modal-title">装箱(箱号: {{number}} )内容编辑</h4>
				</div>
				<div class="modal-body">
					<div class="row clearfix">
						<div class="col-md-12 column">
							<div class="alert alert-dismissable alert-info">
								<button type="button" class="close">×</button>
								<p></p>
							</div>
						</div>
					</div>
					<div class="row">
						<div class="col-md-8">
							<div class="panel panel-default">
								<div class="panel-heading">装箱产品</div>
								<table class="table">
									<thead>
									<tr>
										<th></th>
										<th width="50%">产品</th>
										<th>箱规</th>
										<th width="15%">数量</th>
									</tr>
									</thead>
									<tbody>
									<!--遍历这个箱号下的产品-->
									<tr v-for="(item,index) in editprodata.data" v-if="item.prochar_id>0">
										<td>
											<input type="checkbox" v-model="item.check" :value="item.check" @click="oneseldata(item.pro_id,item.prochar_id)">
										</td>
										<td>
											<div class="pro">
												<div class="pro-icon">
													<img :src="item.img_url" border="0" width="48px"
														 height="48px">
												</div>
												<div class="pro-name">
													<small> {{formatUnit(item.prochar_id,'ID') + (item.brand_name ? ' / '+item.brand_name :'')+ (item.model ? ' / '+item.model :'')}}
													</small>
													<br>
													{{item.pro_name}}
												</div>
											</div>
										</td>
										<td align="right">
											{{item.prochar_qty}}<small class="unit">PCS/CTN</small><br>
											{{item.ctn_size}}<small class="unit">CM</small>
										</td>
										<td>
											<!--实际每箱数量-->
											<input min="1" name="reality_qty" type="number" class="form-control text-right" v-model="item.reality_qty">
										</td>
									</tr>
									<tr style="text-align: center;" v-else>
										<td colspan="4" class="no_date">{:strtoupper(lang('no_data'))}</td>
									</tr>
									</tbody>
								</table>
							</div>
						</div>
						<div class="col-md-4">
							<table class="table">
								<tbody>
								<tr>
									<td width="15%">箱号<span class="required"></span></td>
									<td>
										<input min="1" id="editnumber" type="number" class="form-control text-center" :value="editprodata.number">
									</td>
									<td width="15%">箱数<span class="required"></span></td>
									<td>
										<input min="1" id="editctns" type="number" class="form-control text-center" :value="editprodata.ctns">
									</td>
								</tr>
								<tr>
									<td>箱规<span class="required"></span></td>
									<td>
										<input type="text" id="editctn_size" class="form-control text-right" :value="editprodata.ctn_size">
									</td>
									<td>重量<span class="required"></span></td>
									<td>
										<input type="number" id="editctn_kgs" class="form-control text-right" :value="editprodata.ctn_kgs">
									</td>
								</tr>
								<tr>
									<td>备注</td>
									<td colspan="3">
										<textarea id="editremark" rows="5" class="form-control" :value="editprodata.remark"></textarea>
									</td>
								</tr>
								</tbody>
							</table>
						</div>
					</div>

				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">
						<span class="glyphicon glyphicon-remove"></span>取消
					</button>
					<button type="button" class="btn btn-primary" @click="saveprodata" style="padding-left:24px;padding-right:24px">
						<span class="glyphicon glyphicon-floppy-disk"></span>保存装箱单
					</button>
				</div>
			</div>
		</div>
	</div>
</div>



{include file="public/foot"/}
<!-- InstanceBeginEditable name="EditModal" -->
<!--弹窗部分 结束-->
<script>
    var table = new Vue({
        el: '#listboxing',
        data: {
            topdata:{},//头部系信息
            prodata:[],//产品信息
            area_id:'',//待发区
            batch:[],//勾选的产品的索引
            sale_packdata:[],//装箱内容
            num:1,//箱号
            remarkindex:'',//备注索引
            number:'',//备注显示的箱号
            editprodata:[],//点击编辑时，产品数据
            remakspro:'',//箱子的备注
            isdisadble:false,
        },
        computed:{
            //计算合计
            sumnum(){
                var s = 0;
                var m = 0;
                var w = 0;
                this.sale_packdata.forEach(e => {
                    s+= Number(e.ctns);//箱数
                    m+= Number(e.volume*e.ctns);//每一个箱号的体积*箱数
                    w+= Number(e.ctn_kgs);//重量
                });
                return [s,m,w];
            }
        },
        methods: {
            formatUnit: formatUnit,
            //数据所有获取
            getAllList(){
                $('.loding').show();
                var sale_id=this.getQueryString('sale_id');
                $.ajax({
                    url: "/admin/finance/boxerboxing",
                    type: 'post',
                    data: {
                        getdata: '',//获取标志
                        sale_id:sale_id,//销售id
                    },
                    dataType: "json",
                    success: (result) => {
                        $('.loding').hide();
                        this.topdata = result.topdata;//顶部数据
                        this.prodata = result.prodata;//产品数据
                        this.sale_packdata=result.sale_packdata;//装箱数据
                        this.area_id=result.area_id;//待发区id
                    }
                })
            },
            getQueryString(name){
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
                var r = window.location.search.substr(1).match(reg);
                if (r != null)return unescape(r[2]);
                return null;
            },
            onesel(index){
                if (this.batch.indexOf(index) == -1) {
                    this.batch.push(index)
                } else {
                    this.batch.splice(this.batch.indexOf(index), 1)
                }
            },
            //编辑产品勾选checkbox
            oneseldata(pro_id,prochar_id){
                this.editprodata.data.forEach(item=>{
                    if(item.pro_id==pro_id && item.prochar_id==prochar_id){
                        item.check!=item.check
                    }
                })
            },
            //箭头装箱
            addpro(index){
                if(index==-1){
                    //空箱装箱
                    this.sale_packdata.push({
                        id:'',
                        number:this.num,//箱号
                        ctns:1,//箱数
                        data:[{
                            img_url:'/icon/0000/0000_48.jpg',//空箱默认图片
                            pro_id:'0',//默认产品id
                            prochar_id:'0',//角色id
                            reality_qty:0,//实际每箱装的数量
                            check:true,
                        }],
                        ctn_size:'50*40*30',
                        ctn_kgs:this.formatUnit(10,'KGS'),//重量
                        volume:0.06,//每个箱子体积
                        remark:this.remakspro,//备注
                    });
                    this.num=this.num+1;
                }else {
                    var overqty=this.prodata[index]['quantityqty'];//未装数量
                    var pcsqty= this.prodata[index]['prochar_qty'];//默认每箱数量
                    var floorqty=Math.floor(overqty/pcsqty);//箱数
                    var pcskgs=this.prodata[index]['ctn_kgs']/pcsqty;//每个产品的重量
                    var volume=	Number(this.prodata[index]['ctn_m3']);//每个箱子的体积
                    var ctn_size=this.prodata[index]['ctn_size'];//每个箱子的规格
                    if(overqty>=pcsqty){
                        //表示够装一箱
                        var weight=floorqty*pcsqty*pcskgs;//箱数*每箱装的数量*产品每个重量=装箱重量
                        var reality_qty=pcsqty;//每箱数量
                        var ctn=floorqty;//装箱数
                    }else {
                        //将余量装一箱
                        var weight=overqty*pcskgs;//余量*产品每个重量=装箱重量
                        var reality_qty=overqty;//余量（装一箱）
                        var ctn=1;//装箱数
                    }
                    //这里是选择的是产品
                    this.sale_packdata.push({
                        id:'',
                        number:this.num,//箱号
                        ctns:ctn,//箱数
                        data:[{
                            img_url:this.prodata[index]['img_url'],
                            pro_id:this.prodata[index]['pro_id'],
                            prochar_id:this.prodata[index]['prochar_id'],
                            brand_name:this.prodata[index]['brand_name'],
                            model:this.prodata[index]['model'],
                            pro_name:this.prodata[index]['pro_name'],
                            ctn_size:ctn_size,
                            prochar_qty:pcsqty,//每箱装的数量
                            reality_qty:reality_qty,//实际每箱装的数量
                            check:true,
                        }],//备注
                        ctn_size:ctn_size,//产品箱规
                        ctn_kgs:this.formatUnit(weight,'KGS'),//装箱重量
                        volume:volume,//每个箱子体积
                        remark:'',//备注
                    });
                    this.num=this.num+ctn;//更新箱号
                    //获取最新未装数量
                    this.changeqty();
                }
            },
            //备注点击
            remark(index){
                if(index!=-1){
                    //点击右侧备注
                    this.remarkindex=index;
                    this.number= this.sale_packdata[index]['number'];//备注箱号
                    this.remakspro=this.sale_packdata[index]['remark'];//备注
                }else {
                    this.remarkindex=-1;
                    this.number= '';//备注箱号
                    this.remakspro='';//备注
                }
                $('.modal-body .alert').hide()
                $('.modal-body .alert p').html()
            },
            //保存备注给对应的箱号
            saveremark(){
                if(!this.remakspro){
                    change_mes_type('.modal-body .alert', 2)
                    $('.modal-body .alert').show()
                    $('.modal-body .alert p').html('*备注不能为空' + '<br>')
                }else {
                    if(this.remarkindex==-1){
                        //左侧备注点击
                        this.addpro(-1);
                    }else {
                        //右侧移动备注
                        this.sale_packdata[this.remarkindex]['remark']= this.remakspro;
                    }
                    $('#box_remarkModal').modal('hide');
                }
            },
            //添加到装箱单
            addpack(){
                if(this.batch.length==0){
                    //表示没有勾选产品
                    change_mes_type('#headeralert', 2)
                    $('#headeralert').show()
                    $('#headeralert p').html('*请勾选产品<br>')
                }else if(this.batch.length==1){
                    //勾选一个产品
                    var overqty=this.prodata[this.batch]['quantityqty'];//未装数量
                    var pcsqty= this.prodata[this.batch]['prochar_qty'];//每箱数量
                    var floorqty=Math.floor(overqty/pcsqty);//箱数
                    var pcskgs=this.prodata[this.batch]['ctn_kgs']/pcsqty;//每个产品的重量
                    var volume=	Number(this.prodata[this.batch]['ctn_m3']);//每一个箱子的体积
                    var ctn_size=this.prodata[this.batch]['ctn_size'];//每一个箱子的规格
                    if(overqty>=pcsqty){
                        //表示够装一箱
                        var weight=floorqty*pcsqty*pcskgs;//箱数*每箱装的数量*产品每个重量=装箱重量
                        var reality_qty=pcsqty;//每箱数量
                        var ctn=floorqty;//装箱数
                    }else {
                        var weight=overqty*pcskgs;//余量*产品每个重量=装箱重量
                        var reality_qty=overqty;//余量（装一箱）
                        var ctn=1;//装箱数
                    }
                    this.sale_packdata.push({
                        id:'',
                        number:this.num,//箱号
                        ctns:ctn,//箱数
                        data:[{
                            img_url:this.prodata[this.batch]['img_url'],
                            pro_id:this.prodata[this.batch]['pro_id'],
                            prochar_id:this.prodata[this.batch]['prochar_id'],
                            brand_name:this.prodata[this.batch]['brand_name'],
                            model:this.prodata[this.batch]['model'],
                            pro_name:this.prodata[this.batch]['pro_name'],
                            ctn_size:ctn_size,
                            prochar_qty:pcsqty,//每箱装的数量
                            reality_qty:reality_qty,//实际每箱装的数量
                            check:true,
                        }],//备注
                        ctn_size:ctn_size,//产品箱规
                        ctn_kgs:this.formatUnit(weight,'KGS'),//装箱重量
                        volume:volume,//每个箱子体积
                        remark:'',//备注
                    });
                    this.num=this.num+ctn;//更新箱号
                    //获取最新未装数量
                    this.changeqty();
                    this.batch=[];
                    $('table input').prop('checked', false)
                }else{
                    var ctn_kgs=0;//重量
                    var data = [];//产品
                    //这是勾选多个产品
                    for (i in this.batch){
                        var reality_qty= this.prodata[i]['quantityqty']//未装的数量也表示装箱数量
                        var pcsqty=this.prodata[i]['prochar_qty'];//每箱数量
                        var pcskgs=this.prodata[i]['ctn_kgs']/pcsqty;//每个产品的重量
                        data.push({
                            img_url:this.prodata[i]['img_url'],
                            pro_id:this.prodata[i]['pro_id'],
                            prochar_id:this.prodata[i]['prochar_id'],
                            brand_name:this.prodata[i]['brand_name'],
                            model:this.prodata[i]['model'],
                            pro_name:this.prodata[i]['pro_name'],
                            ctn_size:this.prodata[i]['ctn_size'],//产品规格
                            prochar_qty:pcsqty,//每箱装的数量
                            reality_qty:reality_qty,//实际每箱装的数量
                            check:true,
                        })
                        ctn_kgs+=reality_qty * pcskgs;//装箱的产品数量*每一个产品重量
                    }
                    this.sale_packdata.push({
                        id:'',
                        number:this.num,//箱号
                        ctns:1,//箱数
                        data:data,//产品信息
                        ctn_size:'50x40x30',//产品规格
                        ctn_kgs:this.formatUnit(ctn_kgs,'KGS'),//装箱重量
                        volume:0.06,//每个箱子体积
                        remark:'',//备注
                    })
                    this.num=this.num+1//更新箱号
                    //获取最新未装数量
                    this.changeqty();
                    this.batch=[];
                    $('table input').prop('checked', false)
                }
            },
            //删除 箱号索引  产品索引
            delpack(index,itemdataIndex,code){
                //移除这个箱号下的产品
                this.sale_packdata[index]['data'].splice(itemdataIndex, 1);
                //是否移除这个箱号
                if(code==1){
                    //箱号下没有产品了，同样删除这个箱号
                    if(this.sale_packdata[index]['data'].length==0){
                        this.sale_packdata.splice(index, 1);
                    }
                }
                //获取最新未装数量
                this.changeqty();
            },
            //更新产品的未装数量
            changeqty(){
                this.prodata.forEach(e=>{
                    var qtys=0;
                    this.sale_packdata.forEach(item=>{
                        item.data.forEach(items=>{
                            if(items.pro_id==e.pro_id && items.prochar_id==e.prochar_id){
                                //产品已装数量累加
                                qtys+=item.ctns*items.reality_qty;
                            }
                        })
                    })
                    e.quantityqty=e.qty-qtys;
                })
            },
            //编辑对应的箱号
            editpro(index){
                this.remarkindex=index;
                this.number=this.sale_packdata[index]['number'];//编辑箱号
                //编辑的箱子产品数据
                this.editprodata=this.sale_packdata[index];
                $('.modal-body .alert').hide()
                $('.modal-body .alert p').html()
            },
            //产品编辑后的保存的保存
            saveprodata(){
                var countpro=0;
                //表示编辑的时候是存在产品
                this.editprodata.data.forEach((element, index) => {
                    if(element.pro_id && element.prochar_id && element.check==true){
                        countpro++
                    }
                });
                if(countpro==0){
                    //有产品，但是一个没有勾选
                    if(!$('#editremark').val()){
                        change_mes_type('.modal-body .alert', 2)
                        $('.modal-body .alert').show()
                        $('.modal-body .alert p').html('*备注不能为空' + '<br>')
                        return false;
                    }else {
                        this.sale_packdata[this.remarkindex]['number']=$('#editnumber').val();//箱号
                        this.sale_packdata[this.remarkindex]['ctns']=$('#editctns').val();//箱数
                        this.sale_packdata[this.remarkindex]['ctn_size']=$('#editctn_size').val();//箱规
                        this.sale_packdata[this.remarkindex]['ctn_kgs']=$('#editctn_kgs').val();//重量
                        this.sale_packdata[this.remarkindex]['remark']=$('#editremark').val();//备注
                        //有备注，有产品，但是一个没有勾选
                        this.sale_packdata[this.remarkindex].data.forEach((element, index) => {
                            if(element.check==false){
                                //箱号索引 产品索引（只是删除产品，不删除箱号）
                                this.delpack(this.remarkindex,index,2);
                            }
                        });
                        //产品删除后，补充一个空箱子
                        var datas=[];
                        datas.push({
                            img_url:'/icon/0000/0000_48.jpg',
                            pro_id:'0',
                            prochar_id:'0',
                            reality_qty:0,//实际每箱装的数量
                            check:true,
                        })
                        this.sale_packdata[this.remarkindex]['data']=datas;
                        this.changeqty();
                        $('#box_editModal').modal('toggle')
                    }
                }else {
                    this.sale_packdata[this.remarkindex]['number']=$('#editnumber').val();//箱号
                    this.sale_packdata[this.remarkindex]['ctns']=$('#editctns').val();//箱数
                    this.sale_packdata[this.remarkindex]['ctn_size']=$('#editctn_size').val();//箱规
                    this.sale_packdata[this.remarkindex]['ctn_kgs']=$('#editctn_kgs').val();//重量
                    this.sale_packdata[this.remarkindex]['remark']=$('#editremark').val();//备注
                    //含有产品
                    this.sale_packdata[this.remarkindex].data.forEach((element, index) => {
                        if(element.check==false){
                            //箱号索引 产品索引 只是移除这个箱号下的产品
                            this.delpack(this.remarkindex,index,1);
                        }
                    });
                    this.changeqty();
                    $('#box_editModal').modal('toggle')
                }
            },
            //对数据的提交保存
            subfun(){
//                this.isdisadble=true;
                $.ajax({
                    url: "/admin/finance/boxerboxing",
                    type: 'post',
                    data: {
                        sale_id:this.getQueryString('sale_id'),
                        prodata:this.prodata,
                        area_id:this.area_id,
                        sale_packdata:this.sale_packdata,
                        savebtn:'',
                        names:this.getQueryString('names')
                    },
                    success: (result) => {
                        data = JSON.parse(result)
                        change_mes_type('#headeralert', data.status)
                        $('#headeralert').show()
                        $('#headeralert p').html(data.msg)
                        if (data.status == 1) {
                            this.getAllList()
                        }
                        this.isdisadble=false;
                    }
                })
            }
        },
        mounted(){
            this.getAllList();//数据
            //编辑
            $('#box_editModal').on('hide.bs.modal', (el) => {
                $('#box_editModal').removeData('bs.modal');
                $(document).unbind('keydown');
                //重新给产品勾选上
                if(this.sale_packdata[this.remarkindex]){
                    this.sale_packdata[this.remarkindex].data.forEach(item=>{
                        if(item.check==false){
                            item.check=true;
                        }
                    });
                }
            });
            $('#box_remarkModal').on('hide.bs.modal', (el) => {
                $('#box_editModal').removeData('bs.modal');
                $(document).unbind('keydown');
                this.number='';//箱号清空
                this.remakspro='';//备注清空
            });
        }
    })
</script>





